<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './../mixins/resize'
import {listYcPie} from "../../../api/dashboard/ycpie";

const animationDuration = 3000

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      MapList:[],
      rows:[],
      name:[],
      count:[],
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    async initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
        await listYcPie().then(response => {
        this.MapList = response.rows;
        // console.log("地图饼状图数据：" + this.MapList);
        // console.log(this.MapList[0].unqulified);
      });
      this.chart.setOption({
        title: {
          text: '总体指标饼状图',
          subtext: '本图展示所有指标的达标情况',
          left: 'center'
        },
        tooltip: {
          trigger: 'item',
          formatter: "{b} : {d}%",
        },
        legend: {
          bottom: 10,
          left: 'center',
          data: ['达标率', '未达标率']
        },
        toolbox: {
          show: true,
          feature: {
            mark: { show: true },
            dataView: { show: true, readOnly: false },
            restore: { show: true },
            saveAsImage: { show: true }
          }
        },
        series: [
          {
            type: 'pie',
            radius: '65%',
            center: ['50%', '50%'],
            selectedMode: 'single',
            itemStyle:{
              normal:{
                label:{
                  show: true,
                  formatter: '{b} : {d}%'
                },
                labelLine :{show:true}
              }
            },
            data: [
              { value: this.MapList[0].qulified,name: '达标率' },
              { value: this.MapList[0].unqulified, name: '未达标率' }
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      })
    }
  }
}
</script>
